-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
w: Implement PCPU and JCPU #53
Conversation
The w manpage defines JCPU as the total CPU time of all processes under a given tty. The PCPU is defined as being the total time being used by the command in the "what" field.
Did you see that some tests fail on macOS? It seems like there is no |
Most functions and tests have been enabled only on Linux, as that's the only platform that they were tested on.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #53 +/- ##
==========================================
- Coverage 49.44% 48.37% -1.08%
==========================================
Files 15 15
Lines 1891 1933 +42
Branches 263 277 +14
==========================================
Hits 935 935
- Misses 808 839 +31
- Partials 148 159 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Only import crates when they're being used on a target platform.
Thanks, I've fixed the issue by only enabling /proc based functions on Linux, as I've only tested them there. |
Changed code based on code review from sylvestre.
Thanks for the detailed and thorough code review sylvestre! I've tested the changes and have committed them. |
Could you please add the comments back? I think your merge brings back the previous issue, the self? |
I removed the self, as was done in #54, to resolve the conflict, I think that's correct? |
The w manpage defines JCPU as the total CPU time of all processes under a given tty. The PCPU is defined as being the total time being used by the command in the "what" field.
For the JCPU implementation, the program creates a hashmap of all terminal numbers and their total time by walking the pid folders in /proc. I don't think this is terrible performance-wise, as execution time is still slightly faster than the original w, when built in release mode.
Total time for a process is calculated by taking the sum of time scheduled in both user mode and kernel mode and dividing that by the system's clock tick.
In terms of tests, I've added a couple of unit tests and updated the test_output_format to make sure the JCPU and PCPU fields are populated, these still need to be formatted, so the tests don't check for formatting.